
/*防Android提示框*/
var toast = new Toast();
function Toast() {
    //提示框的html代码
    var _toast_html = '<div id="floatTS"><div style="width: 100%; height: 100%; background-color: Black; position: fixed;z-index: 9999999999; opacity: 0.3;display:none;"></div><div style="width: 100%; height: 45px; left: 0; top: 50%; position: fixed; z-index:99999999999;"align="center"><div id="TStxt" style = "padding:10px; border-radius:5px; line-height:30px; background-color:Black; color:White; width:200px; display:block; opacity:0.8;"></div></div></div>';
    var maxOpacity = 100; //透明度的最大值
    var opacity = 0; //当前透明度值
    var tWaite = 1000; //弹出提示停留时间(毫秒)
    var tSpeed = 10; //提示框小时速度
    var disOpacity = 0.8; //显示时透明度值

    this.show = function (msg) {
        //先停止等待
        wait.dismiss();
        if ($("#TStxt").length < 1) {
            $("body").prepend(_toast_html);
        }
        else {
            $("#floatTS").css("display", "");
        }
        $("#TStxt").text(msg);
        if (opacity < 1) {
            opacity = maxOpacity;
            this.dismiss();
        } else {
            opacity = maxOpacity;
        }
    }

    //隐藏
    this.dismiss = function () {

        if (opacity < 0) {
            $("#floatTS").css("display", "none");
            return false;
        }
        $("#TStxt").css("opacity", opacity / maxOpacity * disOpacity);
        if (opacity == maxOpacity) {
            opacity--;
            setTimeout(function () { toast.dismiss(); }, tWaite);
        }
        else {
            opacity--;
            setTimeout(function () { toast.dismiss(); }, tSpeed);
        }
    }
}

//等待对话框
var wait = new Wait();
function Wait() {
    //等待框html代码
    var _wait_html = '<div id="floatWait"><div style="width: 100%; height: 100%; background-color: Black; position: fixed;z-index: 9999; opacity: 0.3;display:none;"></div><div style="width: 100%; height: 45px; left: 0; top: 50%; position: fixed; z-index: 1000;"align="center"><div style = "padding:10px; border-radius:5px; line-height:30px; background-color:Black; color:White; width:200px; display:block; opacity:0.8;"><span id = "msg"></span><span id="dot"></span></div></div></div>';
    this.isShow = false;
    this.show = function (msg) {

        if ($("#dot").length < 1) {
            $("body").prepend(_wait_html);
        }
        else {
            $("#floatWait").css("display", "");
        }
        $("#msg").text(msg);
        if (!this.isShow) {
            this.isShow = true;
            this.action();
        }
    }

    //动画
    this.action = function () {

        if ($("#dot").text().length > 5) {
            $("#dot").text("·");
        }
        else {
            $("#dot").text($("#dot").text() + "·");
        }
        if (this.isShow) {
            setTimeout(function () { wait.action(); }, 500);
        }

    }

    this.dismiss = function () {
        this.isShow = false;
        $("#floatWait").css("display", "none");
    }
}


var _weUI = function () {
    this.ToastOK = function () {
        var msg = arguments[0] ? arguments[0] : '操作成功';
        var toast = '\
            <div id="toast" style="display: none;">\
            <div class="weui-mask_transparent"></div>\
            <div class="weui-toast">\
                <i class="weui-icon-success-no-circle weui-icon_toast"></i>\
                <p class="weui-toast__content">'+ msg + '</p>\
            </div>\
        </div>';

        if (!$('#toast').length) {
            $('body').append(toast);    //第一次加载
        } else
            $('#toast.weui_toast_content').html(msg);

        $('#toast').fadeIn('fast', function () {
            setTimeout(function () {
                $('#toast').fadeOut('fast');
            }, 800);
        });
    }

    this.Confirm = function (content, callback, cacel_title, ok_title) {
        var msg = arguments[0] ? arguments[0] : '操作成功';
        cacel_title = arguments[2] ? arguments[2] : '取消';
        ok_title = arguments[3] ? arguments[3] : '确定';
        var toast = '\
        <div id="we_dialogs">\
		    <div class="js_dialog" id="iosDialog1" style="display: none;">\
			    <div class="weui-mask"></div>\
			    <div class="weui-dialog">\
				    <div class="weui-dialog__bd">' + content + '</div>\
				    <div class="weui-dialog__ft">\
					    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default">' + cacel_title + '</a>\
					    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">' + ok_title + '</a>\
				    </div>\
			    </div>\
		    </div>\
	    </div>';

        if (!$('#we_dialogs').length) {
            //第一次加载
            $('body').append(toast);
            $('#we_dialogs').on('click', '.weui-dialog__btn', function () {
                if ($(this).attr("class").indexOf("btn_primary") > -1) {
                    callback(); //确认按钮 
                }
                $(this).parents('.js_dialog').fadeOut(200);
            });

        } else {
            $('#iosDialog1 .weui-dialog__bd').html(content);
            $('#iosDialog1 .weui-dialog__btn_default').html(cacel_title);
            $('#iosDialog1 .weui-dialog__btn_primary').html(ok_title);
        }

        $('#iosDialog1').fadeIn(200);   //隐藏弹出框
    }
}

var weUI = new _weUI();